import React, { Component } from 'react';
import { base } from 'nc-lightapp-front';
const { NCRefreshBtn, NCDiv } = base;

class HeadArea extends Component {
    static comName = 'BillList.HeadArea';
    constructor() {
        super();
    }

    handleClick() {
        if (this.props.refreshButtonEvent) {
            this.props.refreshButtonEvent();
        }
    }

    render() {
        let buttonGroup, headCenterCustom, nonstandardButtonGroup;
        const { children } = this.props;
        const { ncProps } = window._ssc_gy_profile;

        React.Children.forEach(children, (child) => {
            if (child && child.type) {
                switch (child.type.comName) { //此处获取函数名不兼容。后续处理
                    case 'ButtonGroup':
                        buttonGroup = child;
                        break;
                    case 'BillList.HeadCenterCustom':
                        headCenterCustom = child
                        break;
                    case 'NonstandardButtonGroup':
                        nonstandardButtonGroup = child;
                        break;
                    default:
                        console.warn('ProfileHead组件内，对子组件：', child, '不做处理')
                }
            }

        });

        const { createBillHeadInfo } = ncProps.BillHeadInfo;
        return (
            <NCDiv className="nc-bill-header-area" areaCode={NCDiv.config.HEADER}>
                <div className="header-title-search-area">
                    {createBillHeadInfo({
                        title: this.props.title,
                        initShowBackBtn: (this.props.back || {}).showBack || false,
                        backBtnClick: (this.props.back || {}).onClick || (()=>{
                            ncProps.pushTo("/list", {
                                pagecode: this.props.back.listPagecode
                            });
                        })
                    })}
                </div>
                <div className="header-middle">
                    {headCenterCustom}
                </div>
                <div className="header-button-area">
                    {buttonGroup}
                    {nonstandardButtonGroup}
                </div>
                {(this.props.refreshButtonEvent && (this.props.status != 'edit')) &&  <NCRefreshBtn disabled={this.props.status === 'browse' ? false : true} style={{ cursor : 'pointer'}} onClick={ this.handleClick.bind(this) }></NCRefreshBtn>}
            </NCDiv>

        )
    }
}

export default HeadArea
